//
//  TraceNodeMakerTests.m
//  UnitTests
//
//  Created by Jiang on 2018/10/22.
//  Copyright © 2018 jiang. All rights reserved.
//

#import <XCTest/XCTest.h>

@interface TraceNodeMakerTests : XCTestCase

@end

@implementation TraceNodeMakerTests
- (void)testTraceCalculate {
    TraceNodeMaker *maker = [[TraceNodeMaker alloc] initWithMin:15 max:15 talks:[DataInputer littleTestData]];
    XCTAssertEqual(maker.totalSchemeCount, 4, @"方案总数");
    XCTAssertEqual(maker.traceNodes.count, 4, @"路线总数");
    XCTAssertEqual(maker.traceNodes.count, maker.totalSchemeCount, @"方案总数等于路线总数");
    [self verifyMakeNodes:maker];
    
    TraceNodeMaker *maker1 = [[TraceNodeMaker alloc] initWithMin:10 max:15 talks:[DataInputer littleTestData]];
    XCTAssertEqual([maker1 schemeCountForTime:maker1.minDuration], 4, @"%d方案总数",maker1.minDuration);
    XCTAssertEqual([maker1 schemeCountForTime:maker1.maxDuration], 4, @"%d方案总数",maker1.maxDuration);
    XCTAssertEqual(maker1.traceNodes.count, maker1.totalSchemeCount, @"方案总数等于路线总数");
    [self verifyMakeNodes:maker1];
    
    TraceNodeMaker *maker2 = [[TraceNodeMaker alloc] initWithMin:120 max:120 talks:[DataInputer normalTestData]];
    XCTAssertEqual(maker2.totalSchemeCount, 8, @"方案总数");
    XCTAssertEqual(maker2.traceNodes.count, 8, @"路线总数");
    XCTAssertEqual(maker2.traceNodes.count, maker2.totalSchemeCount, @"方案总数等于路线总数");
    [self verifyMakeNodes:maker2];
    
    TraceNodeMaker *maker3 = [[TraceNodeMaker alloc] initWithMin:60 max:120 talks:[DataInputer normalTestData]];
    XCTAssertEqual([maker3 schemeCountForTime:maker3.minDuration], 4, @"%d方案总数",maker3.minDuration);
    XCTAssertEqual([maker3 schemeCountForTime:maker3.maxDuration], 8, @"%d方案总数",maker3.maxDuration);
    XCTAssertEqual(maker3.traceNodes.count, maker3.totalSchemeCount, @"方案总数等于路线总数");
    [self verifyMakeNodes:maker3];
    
    TraceNodeMaker *maker4 = [[TraceNodeMaker alloc] initWithMin:180 max:180 talks:[DataInputer exampleTestData]];
    XCTAssertEqual(maker4.totalSchemeCount, 1467, @"方案总数");
    XCTAssertEqual(maker4.traceNodes.count, 1467, @"路线总数");
    XCTAssertEqual(maker4.traceNodes.count, maker4.totalSchemeCount, @"方案总数等于路线总数");
    [self verifyMakeNodes:maker4];
    
    TraceNodeMaker *maker5 = [[TraceNodeMaker alloc] initWithMin:180 max:240 talks:[DataInputer exampleTestData]];
    XCTAssertEqual([maker5 schemeCountForTime:maker5.minDuration], 1467, @"%d方案总数",maker5.minDuration);
    XCTAssertEqual([maker5 schemeCountForTime:maker5.maxDuration], 4980, @"%d方案总数",maker5.maxDuration);
    XCTAssertEqual(maker5.traceNodes.count, 25544, @"路线总数");
    XCTAssertEqual(maker5.traceNodes.count, maker5.totalSchemeCount, @"方案总数等于路线总数");
    [self verifyMakeNodes:maker5];
}
- (void)verifyMakeNodes:(TraceNodeMaker *)maker{
    for (TraceNode *node in maker.traceNodes) {
        [self verifyNode:node maker:maker];
    }
}
- (void)verifyNode:(TraceNode *)node maker:(TraceNodeMaker *)maker{
    int total = 0;
    for (id <Talk>atalk in node.talks) {
        total += atalk.duration;
    }
    if (maker.maxDuration == maker.minDuration) {
        XCTAssertEqual(total, maker.maxDuration,@"'固定时长会议: 单条路线时长应该等于会议总时长'");
    }else{
        XCTAssertGreaterThanOrEqual(total, maker.minDuration,@"范围时长会议: 单条路线时长应该大于等于会议最小时长");
        XCTAssertLessThanOrEqual(total, maker.maxDuration,@"范围时长会议: 单条路线时长应该小于等于会议最大时长");
    }
}


- (void)testPerformanceExample {
    [self measureBlock:^{
        TraceNodeMaker *maker1 = [[TraceNodeMaker alloc] initWithMin:180 max:180 talks:[DataInputer exampleTestData]];
        TraceNodeMaker *maker2 = [[TraceNodeMaker alloc] initWithMin:180 max:240 talks:[DataInputer exampleTestData]];
        NSArray * _ = maker1.traceNodes;
        _ = maker2.traceNodes;
    }];
}

@end
